//msp430-gcc -mmcu=msp430g2231 -o main.elf main.c // mspdebug rf2500

#include <msp430.h>
#include <msp430g2231.h>
#include <string.h>
#include <stdint.h>
#include "uart.h"

#define LED1 BIT0
#define LED2 BIT6

//port2
#define RST BIT1
#define CS BIT0
#define RS BIT2

//port1
#define SDA BIT7
#define SCL BIT6

//input
#define ADCIn BIT3

#define p1on(x) {P1OUT |= x;}
#define p1off(x) {P1OUT &= ~x;}
#define p2on(x) {P2OUT |= x;}
#define p2off(x) {P2OUT &= ~x;}

void delayd(unsigned int);

uint8_t counter = 0;

int main(void)
{
	WDTCTL = WDTPW + WDTHOLD;		//stop watchdog timer
	
	BCSCTL1 = CALBC1_1MHZ;
	DCOCTL = CALDCO_1MHZ;
	BCSCTL2 = DIVS_2 + DIVM_0;
	
	P1DIR |= LED1 + LED2;
	P1OUT |= LED1 + LED2;
	
	p1off(LED1 + LED2);

	uart_init();

	__enable_interrupt();

	uart_puts("\n\r***************\n\r");
	uart_puts("MSP430 softuart\n\r");
	uart_puts("***************\n\r\n\r");

	int c;

	while(1)
	{
		c = counter++%65535;
		uart_puts("Counter: ");
		p1on(LED1);
		uart_putc(c);
		p1off(LED1);
		uart_puts("\n");
	}
}

void delayd(unsigned int d)
{
	while(d--);
}

